package com.markerhub.controller;


import com.markerhub.common.ResponseJson;
import com.markerhub.entity.Blog;
import com.markerhub.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
@Api(value = "CommentController",tags = "博客评论接口")
@RestController
@RequestMapping("/comment")
public class CommentController {
     @Autowired
     CommentService commentService;

    @ApiOperation(value = "根据博客id查询评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "blogId",value = "博客id",required = true,dataType = "int")
    })
    @GetMapping("/get_comments")
    public Object getCommentList(Integer blogId){
        try{
            return ResponseJson.success(commentService.getCommentList(blogId));
        }catch (Exception e)
        {
            return ResponseJson.failure(e.getMessage());
        }
    }

    @ApiOperation(value = "删除评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId",value = "评论id",required = true,dataType = "int"),
            @ApiImplicitParam(name = "blogId",value = "博客id",required = true,dataType = "int")
    })
    @DeleteMapping("/delete_comment")
    public Object getCommentList(Integer commentId,Integer blogId){
        try{
            commentService.deleteComment(commentId,blogId);
            return ResponseJson.success();
        }catch (Exception e)
        {
            return ResponseJson.failure(e.getMessage());
        }
    }

    @ApiOperation(value = "添加评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid",value = "用户d",required = true,dataType = "int"),
            @ApiImplicitParam(name = "blogId",value = "博客id",required = true,dataType = "int"),
            @ApiImplicitParam(name = "content",value = "评论类容",required = true,dataType = "string"),
            @ApiImplicitParam(name = "parentCommentId",value = "上级评论id",required = true,dataType = "int")
    })
    @PostMapping("/add_comment")
    public Object addComment(Integer uid,Integer blogId,String content,Integer parentCommentId){
        try{
            commentService.addComment(uid,blogId,content,parentCommentId);
            return ResponseJson.success();
        }catch (Exception e)
        {
            return ResponseJson.failure(e.getMessage());
        }
    }
}
